package com.bangdream.michelia.model;

import com.alibaba.fastjson.JSON;
import com.bangdream.michelia.application.AppCurrentUser;
import com.bangdream.michelia.contract.LiveContract;
import com.bangdream.michelia.tool.retrofithttp.RetroFactory;
import com.bangdream.michelia.utils.L;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @date on 2018/8/1 23:40
 * @email 909732184@qq.com
 */
public class ILiveModelImpl implements LiveContract.ILiveModel{
    @Override
    public Observable getLiveList(Map<Object, Object> paramsMap) {
        String jsonString = JSON.toJSONString(paramsMap);
        L.d(jsonString);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),jsonString);
        return RetroFactory.getInstance().getLiveList(AppCurrentUser.getInstance().getToken(),
                requestBody);
    }

    @Override
    public Observable getLiveDetails(String id) {
        L.d("id="+id);
        return RetroFactory.getInstance().getLiveDetails(AppCurrentUser.getInstance().getToken(), id);
    }

    @Override
    public Observable getLiveUrl(String token ,String name,String id) {
        Map map=new HashMap();
        map.put("appName",name);
        map.put("streamName",id);
        L.d(JSON.toJSONString(map));
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),JSON.toJSONString(map));
        return RetroFactory.getInstance().getLiveUrl(token,requestBody);
    }

    @Override
    public Observable getReplayLiveUrl(String token, String id) {
        Map map=new HashMap();
        map.put("streamName",id);
        L.d(JSON.toJSONString(map));
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),JSON.toJSONString(map));
        return RetroFactory.getInstance().getReplayLiveUrl(token,requestBody);

    }
}
